import { wxRequest } from '../../../utils/server.js';
const _wxRequest = new wxRequest();
const app = getApp()

Page({
  data: {
    imgUrl:app.globalData.imgUrl,
    datalist: [],
    pageNo: 1
  },

  onLoad: function (options) {
    console.log(options)
    this.setData({
      orgType: Number(options.orgType)
    },function(){
      this.getlist();
    })
    
  },

  // 获取列表
  getlist: function () {
    var that = this   
    _wxRequest.wxTonkenAjax({
      url: app.globalData.apiUrl + '/org/protected/bizOrg/findBizOrg',
      method: 'POST',
      data: {
        orgType: this.data.orgType,
        orgId: wx.getStorageSync('userInfo').orgId,
        keyword: that.data.keywords,
        pageNo: this.data.pageNo,
        pageSize: 20
      }
    }, (res) => {
      console.log(res,'商业组织')
      this.data.hasNextPage = res.page.hasNextPage
      this.data.pageNo = res.page.pageNo
      this.setData({
        datalist: this.data.datalist.concat(res.list)
      })
    })
  },

  onReachBottom: function () {
    if (this.data.hasNextPage) {
      this.data.pageNo++
      this.getlist()
    }
  },


  //监听搜索
  seacherOn: function (e) {
    var keywords = e.detail
    this.setData({
      keywords
    })
    this.getlist()
  },


  //选择供应商
  choose: function (e) {
    console.log('choose', e)
    var item = e.currentTarget.dataset.item
    console.log('item:', item)
    //直接调用上一个页面的setData()方法，把数据存到上一个页面中去
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2]; //上一个页面    
    prevPage.setData({
      bizOrgItem: item,
    })
    wx.navigateBack();
  },
})